<?php
//echo md5("Lillehammer2010");die;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of system_controller
 *
 * @author phamhphuc
 */
class system_controller_admin extends system_controller {
    public $isAdmin = true;
    public function __construct($config) {              
        $this->config = $config;                                
        if(isset($config['default_action'])) {
            $this->action = $config['default_action'];
        }
        $this->view = new system_view();        
        $this->session = new system_session($config, "etc_admin_");
        
        if($this->session->user){
            $this->config['user_id'] = $this->session->user['user_id'];
        }
        
        $this->db = new system_db($config);                       
        $this->_setupData();     
        $this->setupSettings();
        $this->init();        
    } 
    
    public function init(){
        parent::init();
        
//        echo "<pre>";print_r($this->config);die;
        
        if(!$this->config['use_aws_template_storage_backend']) {
            $this->view->layoutUrl = "../../../admin/templates/{$this->config['template_name']}/layouts/";            
        } else {
            $this->view->layoutUrl = "{$this->config['aws_template_admin_url']}{$this->config['template_name']}/layouts/";
        }
        $this->view->layoutUrlLocal = "../../../admin/templates/{$this->config['template_name']}/layouts/";
        // check for login
        if(!$this->session->user){
            if(isset($_REQUEST['action'])) {
                $this->action = $_REQUEST['action'];
            }
            if($this->action != "login" && $this->action != "signup") {               
                header("location: ?action=login");
            }
        } else {
            $this->config['user_id'] = $this->session->user['user_id'];
            $this->view->user = $this->session->user;            
        }
    }
    
    public function getTemplateDir(){
        if($this->config['template_name']) {
            return "../../../admin/templates/{$this->config['template_name']}/";
        }
        return "";
    }
    
    public function getTemplateURL(){
        if($this->config['template_name']) {
            return "../../../admin/templates/{$this->config['template_name']}/";
        }
        return "";
    }

}

?>
